package zgh.prototype;

/**
 * 用原型模式生成奖状
 * 获奖人除了姓名不同，其他都相同，属于相似对象的复制，同样可以用原型模式创建，然后再做简单修改就可以
 */
public class ProtoTypeCitation {

    public static void main(String[] args) throws CloneNotSupportedException {

        citation citation = new citation("张三", "三好学生", "第三中学");
        citation.display();
        citation citation1 = (citation) citation.clone();
        citation1.setName("李四");
        citation1.display();

    }

}

/**
 * 奖状类
 */
class citation implements Cloneable {
    String name;
    String info;
    String college;

    public citation(String name, String info, String college) {
        this.name = name;
        this.info = info;
        this.college = college;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    void display(){
        System.out.println(name + info+ college);
    }

    @Override
    public Object clone() throws CloneNotSupportedException {
        System.out.println("奖状拷贝成功!");
        return (citation)super.clone();
    }

}
